package de.herberlin.webapp.image.transform;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;


public class CutOverlappingTransformer implements Transformer {

	
	public CutOverlappingTransformer(){}
	public BufferedImage transform(BufferedImage original, BufferedImage target) {

		float deltaWidth= ((float)target.getWidth()) / ((float)original.getWidth());
		float deltaHeight= ((float)target.getHeight()) / ((float)original.getHeight());
		
		float overallDelta= Math.max(deltaWidth, deltaHeight);
		
		((Graphics2D)target.getGraphics()).drawImage(original,
				(int)((deltaWidth-overallDelta) * original.getWidth() / 3),
				(int)((deltaHeight-overallDelta) * original.getHeight() / 3),
				(int)(original.getWidth()*overallDelta),
				(int)(original.getHeight()*overallDelta),null);
		
		return target;
	}

}
